﻿<!--#include virtual="/Common/Config.asp" -->
<!--#include virtual="/Common/conn.asp" -->
<!--#include virtual="/2010admin/Check_IsLogin.asp" -->
<!--#include virtual="/Common/Function.asp" -->
<!--#include virtual="/2010admin/Check_Priv.asp"-->

<%
If Request.ServerVariables ("Request_Method")="POST" Then

	'禁止从网站外部提交数据
	Call Deny_OutSiteSubit()

	action = requery("action")

	Select Case action
			Case "add"  Call Sys_Item_Add()	
			Case "edit" Call Sys_Item_Edit()	
			Case "del"  Call Sys_Item_Del()
	End Select
End If

Function Sys_Item_Add()

	sDI_Name = reform("sDI_Name")
	
	Call Check_Length(sDI_Name,5000,1,"项目名称")
	
	DI_Name_Array = Split(sDI_Name,",")

	'检查数据
	For i=0 To UBound(DI_Name_Array)
		Call Check_Length(DI_Name_Array(i),10,1,"项目名称")
	Next 

	Max_Order = Get_FirstValue("SELECT ISNULL(Max(DI_Order),0) FROM Dic_Item ")


	Conn.BeginTrans
	On Error Resume Next

	'加入数据
	For i=0 To UBound(DI_Name_Array)
	Sql = "INSERT INTO Dic_Item(DI_Name,DI_Order) VALUES("&_
		  "'"&DI_Name_Array(i)&"'"&_
		  ","&(Max_Order+i+1)&_	
		  ")"
		conn.execute(sql)

	Next 

	if err.number =0 then  
	    conn.CommitTrans  
		AlertBox "增加成功!","Sys_Item_Query.asp"
	else 
		conn.RollbackTrans 
		AlertBox "增加失败！","Sys_Item_Query.asp"
	end if

End Function 


Function Sys_Item_Edit()

	DI_ID_Str = reform("DI_ID")
	
	If DI_ID_Str="" Then
		AlertBox "请选择要修改的记录!","javascript:history.go(-1)"	
	End If
	
	'ENDD
	DI_ID_Array = Split(DI_ID_Str,",")
	For i=0 To UBound(DI_ID_Array)

		iDI_ID = Trim(CStr(DI_ID_Array(i)))

		sDI_Name = reform("DI_Name"&iDI_ID)
		sDI_Value = reform("DI_Value"&iDI_ID)
		iDI_Order= reform("DI_Order"&iDI_ID)
		
		Call Check_Length(sDI_Name,10,1,"项目名称")
		Call Check_Length(sDI_Value,2000,0,"项目内容")
		Call Check_IsNumeric(iDI_Order)

	Next


	Conn.BeginTrans
	On Error Resume Next

	For i=0 To UBound(DI_ID_Array)

		iDI_ID = Trim(DI_ID_Array(i))
		sDI_Name = reform("DI_Name"&iDI_ID)
		sDI_Value = reform("DI_Value"&iDI_ID)
		iDI_Order= reform("DI_Order"&iDI_ID)

		Sql = "UPDATE Dic_Item SET DI_Name='"&sDI_Name&"'"&_
			  ",DI_Value='"&sDI_Value&"'"&_
			  ",DI_Order="&iDI_Order&_
			  "WHERE DI_ID="&iDI_ID

		conn.execute(sql)


	Next
	
	if err.number =0 then  
	    conn.CommitTrans  
		AlertBox "修改成功!","Sys_Item_Query.asp"	
	else 
		conn.RollbackTrans 
		AlertBox "修改失败！","Sys_Item_Query.asp"
	end if

End Function 

Function Sys_Item_Del()

	iDI_ID = reform("DI_ID")

	'Call Check_IsNumeric(iDI_ID)


	Sql = "DELETE FROM Dic_Item WHERE DI_ID IN ("&iDI_ID &");"
	Sql = Sql &" DELETE FROM DIC_Sub_Item WHERE DI_ID IN ("&iDI_ID &");"
	
	conn.execute(sql)

	
	AlertBox "删除成功!","Sys_Item_Query.asp"	

End Function 


%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="/2010admin/css/default.css" type="text/css" rel="stylesheet">
<title><%=web_title%></title>
<script language="javascript" src="/js/main.js"></script>
<script language="javascript" src="/js/selects.js"></script>
<script language="javascript" src="/js/manage.js"></script>
<script language="javascript" src="/2010admin/js/validator.js"></script>

<script language="javascript"> 
function checkall(field)
{
  var sall = document.form.list2.checked;
  if (field.length)
  {
	slength = field.length;
	for (var i = 0; i < slength; i++) { field[i].checked = sall; }
  }
  else { field.checked = sall; }
}
function checkform()
{
 var groups = document.getElementsByName("DI_ID");
 var hasChecked = 0;
 for(var i=0; i<groups.length;i++)
	if(groups[i].checked) hasChecked++;
	
if(hasChecked==0)
{
	alert("至少选择一条要修改的记录!");
	return false;
}
else document.form.submit();
}
</script> 
<script language="javascript">
<!--
	function delcheck(){
	 var groups = document.getElementsByName("DI_ID");
	 var hasChecked = 0;
	 for(var i=0; i<groups.length;i++)
		if(groups[i].checked) hasChecked++;
		
	if(hasChecked==0)
	{
		alert("至少选择一条要删除的记录!");
		return false;
	}

	if (confirm('是否真的要删除这条记录？')) {
		document.form.action="Sys_Item_Query.asp?action=del";
		document.form.submit();
	}
	else return false;
}
//-->
</script>
</head>
<body >
<table border="0" width="100%" cellSpacing="0" cellPadding="0">
  <tr>
    <td width="100%" height="5"></td>
  </tr>
  <tr>
    <td width="100%" align="center">
      <table border="0" width="98%" cellSpacing="0" cellPadding="0">
        <tr>
          <td width="*" align="center" valign="top">
            <table border="0" width="100%" cellSpacing="0" cellPadding="0" class="lrbtline">
              <tr>
                <td width="100%" height="25" class="tbtop">管理导航</td>
              </tr>
              <tr>
                <td width="100%" align="center">
                  <table border="0" width="98%" cellSpacing="0" cellPadding="0">
                    <tr>
                      <td width="100%" height="5"></td>
                    </tr>
                  </table>
                  <table border="0" width="98%" cellSpacing="0" cellPadding="0">
                    <tr>
                      <td width="100%" height="20">&nbsp;<img src="/2010admin/images/sico.gif" border="0">&nbsp;<span id="userlist"><a href="Sys_Item_Query.asp">项目大类</a></span>&nbsp;&nbsp;<span id="useradd"></span></td>
                    </tr>
                    <tr>
                      <td width="100%" height="5"></td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
            <table border="0" width="100%" cellSpacing="0" cellPadding="0">
              <tr>
                <td width="100%" height="5"></td>
              </tr>
            </table>
			<%
			sql="SELECT DI_ID,DI_Name,DI_Value,DI_Order FROM Dic_Item ORDER BY DI_Order ASC"
			Set rs=conn.execute(sql)

			If Not rs.Eof Then

			%>
            <table border="0" width="100%" cellSpacing="0" cellPadding="0" class="lrbtline">
              <tr>
                <td width="100%" height="25" class="tbtop">修改项目信息</td>
              </tr>
              <tr>
                <td width="100%" align="center">
                  <table border="0" width="98%" cellSpacing="0" cellPadding="0">
                    <tr>
                      <td width="100%" height="5"></td>
                    </tr>
                  </table>
                  <table border="0" width="98%" cellSpacing="0" cellPadding="0">
                  <form action="?action=edit" method="post" name="form" >

                    <tr>
                      <td height="25"><div align="center">选择</div></td>
                      <td>项目名称</td>
                    <td>项目内容</td>
                    <td>顺序</td>
                    <td>编辑子项目</td>
                    </tr>
					<%
					Do While Not rs.Eof 
						DI_ID  =rs(0)
						DI_Name=rs(1)
						DI_Value=rs(2)
						DI_Order=rs(3)
						
					%>
                    <tr>
                      <td width="136" height="25"><div align="center">
                        <input name="DI_ID" type="checkbox" id="DI_ID" value="<%=rs(0)%>" >
                      </div></td>
                      <td width="165">
					  <input name="DI_Name<%=rs(0)%>" type="text" id="DI_Name" value="<%=DI_Name%>" size="20" ></td>
                    <td width="295"><input name="DI_Value<%=rs(0)%>" type="text" id="DI_Value<%=rs(0)%>" value="<%=DI_Value%>" size="40" ></td>
                    <td width="175"><input name="DI_Order<%=rs(0)%>" type="text" id="DI_Order" value="<%=DI_Order%>" size="20" ></td>
                    <td width="429"><a href="Sys_Sub_Item_Query.asp?DI_ID=<%=DI_ID%>">编辑</a></td>
                    </tr>
					<%
					rs.movenext
					Loop
					%>
                    <tr>
                      <td height="25"><div align="center">
 						<input type=checkbox name="list2" onClick="checkall(this.form.DI_ID);"  >

                        </div></td>
                      <td colspan="4"><input type="button" name="button1" value="修改" class="button" onClick="return checkform();">&nbsp;<input type="button" name="button2" value="删除" class="button" onClick="return delcheck();"></td>
                    </tr>
                  </form>
                  </table>
                  <table border="0" width="98%" cellSpacing="0" cellPadding="0">
                    <tr>
                      <td width="100%" height="5"></td>
                    </tr>
                  </table>
			 <%
			 End If 

			 rs.close
			 %>

            <table border="0" width="100%" cellSpacing="0" cellPadding="0" class="lrbtline">
              <tr>
                <td width="100%" height="25" class="tbtop">增加项目</td>
              </tr>
              <tr>
                <td width="100%" align="center">
                  <table border="0" width="98%" cellSpacing="0" cellPadding="0">
                    <tr>
                      <td width="100%" height="5"></td>
                    </tr>
                  </table>
                  <table border="0" width="98%" cellSpacing="0" cellPadding="0">
                  <form action="?action=add" method="post" name="form1" onSubmit="return Validator.Validate(this, 2)">

                    <tr>
                      <td width="137" height="25"><div align="center"></div>
                        项目名称</td>
                      <td><input name="sDI_Name" type="text" id="sDI_Name" value="" size="80" dtype="Limit" min="2" max="5000" dmsg="项目名称必须在2-5000个字符间" >可批量加入，分类之间用英文,分隔</td>
                    </tr>
                    <tr>
                      <td height="25" colspan="2"><div align="center">
                        </div>                        <input type="submit" name="submit1" value="修改" class="button"></td>
                      </tr>
                  </form>
                  </table>

                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td width="100%" height="5"></td>
  </tr>
</table>
</body>
</html>
<%
Call conn_close()
%>

